/**
 * @author psj
 */
//프로필
    function clsProfileView(){
        this._HTMLDom = null;
        this.listData = null;
        this.mUtil = null;  
        this._init();
    }
    
    clsProfileView.prototype = {
        _init: function(){
            var $layer = $("section#profile_view>section");
            this._HTMLDom = {
                "$layer": $layer.find("form>ul")
                , "$img": $layer.find("article.profile_area  div.p_img img")
            }                       
            this.mUtil = document.globalObj.util;
            this.hideBtn();            
            this.showTime().hide();         
        }
         , hideBtn : function(){
             var login_id = document.globalObj.LOGIN_DATA.userId;
             var profile_id = document.globalObj.PROFILE_DATA.userId;
             
             if(login_id == profile_id){
                 $("#send_message_btn").hide();
                 $("#profile_modify_btn").click(function() {
                     console.log("수정 하기 클릭");
                     $.mobile.changePage("profile_modify.html");       
                 });
             }
             else {
                 $("#profile_modify_btn").hide();
                 $("#send_message_btn").click(function() {
                     $.mobile.changePage("../inc/letter_write.html");       
                 });
             }
         }
        , setData: function(thisData){
            this.listData = thisData;
            this.display(); 
        }
        , display: function(){
            var $layer = this._HTMLDom["$layer"];
            var $img = this._HTMLDom["$img"];
            var thsiClass= this;
            var region_str = '';
            switch(this.listData["지역코드"]){
                case  1 :  region_str = '수도권(서울/경기/인천)';
                break;
                case  2 : region_str = '중부권(강원/충청)';
                break;
                case  3 : region_str = '남부권(전라/경상/제주)';
                break;
                default :  region_str = ' ';
            }
            if(this.listData["이미지"]) $img.attr("src", this.mUtil.filePath2Url(this.listData["이미지경로"])+this.listData["이미지"]);
            $("#profileView_nickname").text(this.listData["닉네임"]);
            $("#profileView_age").text(  (this.listData["연령대코드"] != "") ? this.listData["연령대코드"]+"대 이상" : "" );
            $("#profileView_region").text(region_str);
            $("#profileView_job").text(this.listData["직업"]);
            $("#profileView_handi").text(this.listData["핸디"]);
            $("#profileView_average").text(this.listData["평타"]);
            /*
            $img.attr("src", this.listData["이미지"]);
            $layer.find("li:eq(0) div").html(this.listData["닉네임"]);
            $layer.find("li:eq(1) div>select>option").eq(this.listData["연령대코드"]).prop("selected",true)
            $layer.find("li:eq(1) div>select").change();
            $layer.find("li:eq(2) div>select>option").eq(this.listData["지역코드"]).prop("selected",true);
            $layer.find("li:eq(2) div>select").change();
            $layer.find("li:eq(3) div input:text").val(this.listData["직업"]);
            $layer.find("li:eq(4) div input:text").val(this.listData["핸디"]);
            $layer.find("li:eq(5) div input:text").val(this.listData["평타"]);
            */
            this.showTime().show();
        }
        , spinStart: function(){        
            $.mobile.showPageLoadingMsg();          
        }
        , spinEnd: function(){          
            $.mobile.hidePageLoadingMsg();              
        }
        , showTime: function(){
            return $("section#profile_view>section");
        }
    }
/*---------------------------------------------------------------------------------------------------------*/
    function Profile_View(){
        this.profileList = null;   
    }
    Profile_View.prototype = {
        onPageShow : function() {
            /*사용자 로그인체크 
            if(!common.userCheck()){
                alert("로그인 후 사용하시기 바랍니다.");
                return;
            }
            */
          $("a").attr("href","");
          this._init();
        }
         , _init : function(){
            this.objProfile = new clsProfileView();
                   
           //프로필정보 조회
           this.objProfile.spinStart();        
           this.getProfile();
           this._bind();
        }
         , getProfile : function(){
             var thisClass = this;
            //var userId = this.profileListRequest["아이디"];
            console.log(">>>>>>>>>>>>"+document.globalObj.PROFILE_DATA.userId);
            
            var objJson = new MJson();
            var cm = new ConnectionManager();
            objJson.putPub(MJson.PUB.SID, "US001");
            objJson.putPub(MJson.PUB.SERVICENAME, "getMyProfile");
            objJson.putClient(MJson.CLIENT.USERID, document.globalObj.PROFILE_DATA.userId);
    
            cm.requestGet(objJson.getJsonString(), function(data){
                var result = [];
                console.log(data);
                if(data.msp.contents.serviceResult == "00000"){
                    var dataObj = data.msp.contents.items; 
                    console.log(dataObj);
                    //ajax
                    
                    setTimeout(function(){              
                        thisClass.profileList = {
                            "아이디": dataObj.userId
                            , "이미지경로" : dataObj.path
                            , "이미지":  _util.nvl(dataObj["saveFileName"])
                            , "닉네임": dataObj.nickname
                            , "연령대코드": dataObj.age ? dataObj.age : ""
                           // , "연령대명": "30대"
                            , "지역코드": dataObj.region?dataObj.region : ''
                           // , "지역명": "중부권(강원/충청)"
                            , "직업": dataObj.job ? dataObj.job : ''
                            , "핸디":  dataObj.handi ? dataObj.handi : 0
                            , "평타": dataObj.average ? dataObj.average : 0
                        };
                        
                        $(thisClass).trigger("evtFinishProfile");
                    }, 500);  
                }
            }, function($err) {
                console.log("errod >>>>>>>>>");
                console.log($err);
            });
         }
         , getProfileData: function(){
             return this.profileList;    
           }
          , _bind : function(){
              var _this = this;
              //프로필정보 조회 완료이벤트
            $(this).bind("evtFinishProfile", function(event){
                var thisData = _this.getProfileData();
                console.log("====================");
                console.log(thisData);
                _this.objProfile.setData(thisData);
                _this.objProfile.spinEnd();
            });
          }
    }
